$(function () {
    myGetAjax(
        "/catering_system_app/order/selectOrderByUserId",
        {},
        getOrder
    );
    $("#logout_1").click(function () {
        logout();
    });
    //显示商户名
    listShopName();

    //显示用户名
    listname();
});
function selectByState(obj) {
    if (obj!="null"){
        myGetAjax(
            "/catering_system_app/order/selectOrderByUserId",
            {
                stateId:obj
            },
            getOrder
        );
    } else {
        myGetAjax(
            "/catering_system_app/order/selectOrderByUserId",
            {},
            getOrder
        );
    }

}
function getOrder(RespVo) {
    alert(RespVo.code);
    if (RespVo.code= "200") {
        var number;
        var str = "<tr></tr>";
        var allPrice=0.0;
        if (RespVo.data!= null&&RespVo.data!="") {
            for (var i = 0; i < RespVo.data.length; i++) {
                number = RespVo.data.length;
                str += "<tr style='padding-top: 10px'>" +
                    "<td>" + RespVo.data[i].orderId + "</td>" +
                    "<td>" + RespVo.data[i].foodName + "</td>" +
                    "<td><img src='img/" + RespVo.data[i].foodUrl + "' style='width: 50px;height: 30px'></td>" +
                    "<td>" + RespVo.data[i].orderNum + "</td>" +
                    "<td>" + RespVo.data[i].foodPrice + "</td>" +
                    "<td >" + RespVo.data[i].foodAllPrice + "</td>" +
                    "<td class='oneprice'>" + RespVo.data[i].shopName + "</td>" +
                    "<td>"+formatDate(RespVo.data[i].orderCreateTime)+"</td>" +
                    "<td>"+RespVo.data[i].stateName+"</td>";
                "</tr>";
                allPrice += RespVo.data[i].foodAllPrice ;
                $("#orderList").html(str);
            }
        }else {
            $("#orderList").html(str);
        }
        $("#mybuy em").text(number);
        $("#myprice").text("￥"+allPrice)
    } else {
        alert(RespVo.msg)
    }
}
//时间戳转换
function add0(m){return m<10?'0'+m:m }
function formatDate(timestamp)
{
    //timestamp是整数，否则要parseInt转换
    var time = new Date(timestamp);
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
